-- ...So I realize that I completely ignored almost each and every
-- metrics-bound element this screen could use, but it's okay, right?

local t = Def.ActorFrame {};
-- A very useful table...
local eval_lines = {
	"W1",
	"W2",
	"W3",
	"W4",
	"W5",
	"Miss",
	"Held",
	"MaxCombo"
}

-- And a function to make even better use out of the table.
local function GetJLineValue(line, pl)
	if line == "Held" then
		return STATSMAN:GetAccumPlayedStageStats():GetPlayerStageStats(pl):GetHoldNoteScores("HoldNoteScore_Held")
	elseif line == "MaxCombo" then
		return STATSMAN:GetAccumPlayedStageStats():GetPlayerStageStats(pl):MaxCombo()
	else
		return STATSMAN:GetAccumPlayedStageStats():GetPlayerStageStats(pl):GetTapNoteScores("TapNoteScore_" .. line)
	end
	return "???"
end

-- #################################################
-- Player stats and labels 
if GAMESTATE:IsHumanPlayer(PLAYER_1) then 
	local p1evalx = SCREEN_CENTER_X-400
	local p1evaly = SCREEN_TOP+125
	local eval_offset = 44

	for i, v in ipairs(eval_lines) do
	local spacing = 24*i
	local cur_line = "JudgmentLine_" .. v
	local p_grade = STATSMAN:GetAccumPlayedStageStats():GetPlayerStageStats(PLAYER_1):GetGrade()
	
	t[#t+1] = Def.ActorFrame {
		LoadActor(THEME:GetPathG("_grade", "pane")) .. {
			InitCommand=cmd(horizalign,left;x,p1evalx;y,p1evaly);
		};
		LoadActor(THEME:GetPathG("GradeDisplay", "Grade " .. p_grade)) .. {
			InitCommand=cmd(zoom,0.7;horizalign,left;x,p1evalx-24;y,p1evaly+10);
		},
	};
	
	t[#t+1] = Def.ActorFrame {
		OnCommand=cmd(diffusealpha,0;sleep,0.05*i;linear,0.1;diffusealpha,1);
		LoadActor(THEME:GetPathG("_eval", "line")) .. {
			InitCommand=cmd(horizalign,left;x,p1evalx;y,p1evaly+eval_offset+spacing;);
		};
		LoadFont("Common Normal") .. {
			InitCommand=cmd(horizalign,left;zoom,0.7;diffuse,JudgmentLineToColor(cur_line);diffusebottomedge,ColorMidTone(JudgmentLineToColor(cur_line));strokecolor,color("#000000");x,p1evalx+8;y,p1evaly+eval_offset+spacing;settext,string.upper(JudgmentLineToLocalizedString(cur_line)););
		};
		LoadFont("ScoreDisplayNormal Text") .. {
			InitCommand=cmd(horizalign,right;zoom,0.7;diffuse,JudgmentLineToColor(cur_line);diffusebottomedge,ColorMidTone(JudgmentLineToColor(cur_line));x,p1evalx+190;y,p1evaly+eval_offset+spacing-4);
			OnCommand=function(self)
				self:settext(GetJLineValue(v, PLAYER_1))
			end,
		};
	};
	end;
	
		t[#t+1] = Def.ActorFrame {
		InitCommand=cmd(x,p1evalx+100;y,p1evaly+eval_offset+24*9;horizalign,right;);
		OnCommand=cmd(diffusealpha,0;sleep,0.05*9;linear,0.1;diffusealpha,1);
			LoadActor(THEME:GetPathG("_eval", "line")) .. {
			};
			LoadFont("Common Normal") .. {
				InitCommand=cmd(horizalign,left;zoom,0.7;diffuse,Color("White");diffusebottomedge,color("#CACECF");strokecolor,color("#000000");settext,"DP %";addx,-91;);
			};
			LoadFont("ScoreDisplayNormal Text") .. {
				InitCommand=cmd(horizalign,right;zoom,0.7;diffuse,Color("White");diffusebottomedge,color("#CACECF");strokecolor,color("#000000");addy,-4;addx,88);
				OnCommand=function(self)
					self:settext(FormatPercentScore(STATSMAN:GetAccumPlayedStageStats():GetPlayerStageStats(PLAYER_1):GetPercentDancePoints()))
				end;
			};
		};
		t[#t+1] = Def.ActorFrame {
		InitCommand=cmd(x,p1evalx+100;y,p1evaly+eval_offset+24*10;horizalign,right;);
		OnCommand=cmd(diffusealpha,0;sleep,0.05*10;linear,0.1;diffusealpha,1);
			LoadActor(THEME:GetPathG("_small eval", "line")) .. {
			};
			LoadFont("Common Normal") .. {
				InitCommand=cmd(horizalign,left;zoom,0.5;diffuse,Color("White");diffusebottomedge,color("#CACECF");strokecolor,color("#000000");settext,"SCORE";addx,-91;addy,-3);
			};
			LoadFont("ScoreDisplayNormal Text") .. {
				InitCommand=cmd(horizalign,right;zoom,0.5;diffuse,Color("White");diffusebottomedge,color("#CACECF");strokecolor,color("#000000");addy,-6;addx,44);
				OnCommand=function(self)
					self:settext(STATSMAN:GetAccumPlayedStageStats():GetPlayerStageStats(PLAYER_1):GetScore())
				end;
			};
		};
end;

if GAMESTATE:IsHumanPlayer(PLAYER_2) then 
	local p2evalx = SCREEN_CENTER_X+150+81-31
	local p2evaly = SCREEN_TOP+125
	local eval_offset = 44

	for i, v in ipairs(eval_lines) do
	local spacing = 24*i
	local cur_line = "JudgmentLine_" .. v
	local p_grade = STATSMAN:GetAccumPlayedStageStats():GetPlayerStageStats(PLAYER_2):GetGrade()
	
	t[#t+1] = Def.ActorFrame {
		LoadActor(THEME:GetPathG("_grade", "pane")) .. {
			InitCommand=cmd(horizalign,left;x,p2evalx;y,p2evaly);
		};
		LoadActor(THEME:GetPathG("GradeDisplay", "Grade " .. p_grade)) .. {
			InitCommand=cmd(zoom,0.7;horizalign,left;x,p2evalx-24;y,p2evaly+10);
		},
	};
	
	t[#t+1] = Def.ActorFrame {
		OnCommand=cmd(diffusealpha,0;sleep,0.05*i;linear,0.1;diffusealpha,1);
		LoadActor(THEME:GetPathG("_eval", "line")) .. {
			InitCommand=cmd(horizalign,left;x,p2evalx;y,p2evaly+eval_offset+spacing;);
		};
		LoadFont("Common Normal") .. {
			InitCommand=cmd(horizalign,left;zoom,0.7;diffuse,JudgmentLineToColor(cur_line);diffusebottomedge,ColorMidTone(JudgmentLineToColor(cur_line));strokecolor,color("#000000");x,p2evalx+8;y,p2evaly+eval_offset+spacing;settext,string.upper(JudgmentLineToLocalizedString(cur_line)););
		};
		LoadFont("ScoreDisplayNormal Text") .. {
			InitCommand=cmd(horizalign,right;zoom,0.7;diffuse,JudgmentLineToColor(cur_line);diffusebottomedge,ColorMidTone(JudgmentLineToColor(cur_line));x,p2evalx+190;y,p2evaly+eval_offset+spacing-4);
			OnCommand=function(self)
				self:settext(GetJLineValue(v, PLAYER_2))
			end,
		};
	};
	end;
	
		t[#t+1] = Def.ActorFrame {
		InitCommand=cmd(x,p2evalx+100;y,p2evaly+eval_offset+24*9;horizalign,right;);
		OnCommand=cmd(diffusealpha,0;sleep,0.05*9;linear,0.1;diffusealpha,1);
			LoadActor(THEME:GetPathG("_eval", "line")) .. {
			};
			LoadFont("Common Normal") .. {
				InitCommand=cmd(horizalign,left;zoom,0.7;diffuse,Color("White");diffusebottomedge,color("#CACECF");strokecolor,color("#000000");settext,"DP %";addx,-91;);
			};
			LoadFont("ScoreDisplayNormal Text") .. {
				InitCommand=cmd(horizalign,right;zoom,0.7;diffuse,Color("White");diffusebottomedge,color("#CACECF");strokecolor,color("#000000");addy,-4;addx,88);
				OnCommand=function(self)
					self:settext(FormatPercentScore(STATSMAN:GetAccumPlayedStageStats():GetPlayerStageStats(PLAYER_2):GetPercentDancePoints()))
				end;
			};
		};
		t[#t+1] = Def.ActorFrame {
		InitCommand=cmd(x,p2evalx+100;y,p2evaly+eval_offset+24*10;horizalign,right;);
		OnCommand=cmd(diffusealpha,0;sleep,0.05*10;linear,0.1;diffusealpha,1);
			LoadActor(THEME:GetPathG("_small eval", "line")) .. {
			};
			LoadFont("Common Normal") .. {
				InitCommand=cmd(horizalign,left;zoom,0.5;diffuse,Color("White");diffusebottomedge,color("#CACECF");strokecolor,color("#000000");settext,"SCORE";addx,-91;addy,-3);
			};
			LoadFont("ScoreDisplayNormal Text") .. {
				InitCommand=cmd(horizalign,right;zoom,0.5;diffuse,Color("White");diffusebottomedge,color("#CACECF");strokecolor,color("#000000");addy,-6;addx,44);
				OnCommand=function(self)
					self:settext(STATSMAN:GetAccumPlayedStageStats():GetPlayerStageStats(PLAYER_2):GetScore())
				end;
			};
		};
end;

-- if gameplay_pause_count > 0 then
	-- t[#t+1]= Def.BitmapText{
		-- Font= "_roboto condensed 24px",
		-- Text= THEME:GetString("PauseMenu", "pause_count") .. ": " .. gameplay_pause_count,
		-- InitCommand=cmd(x,SCREEN_CENTER_X;y,SCREEN_BOTTOM-100+26;);
		-- OnCommand=function(self)
			-- self:diffuse(color("#ffffff")):zoom(0.8);
			-- self:diffusealpha(0):sleep(0.5):smooth(0.3):diffusealpha(1);
		-- end;
		-- OffCommand=cmd(decelerate,0.3;diffusealpha,0);
	-- }
-- end

return t;

